<extend name='./Base' />
<block name='admin-content-body'>
<link rel="stylesheet" href="__PUBLIC__/static/admin/wangEditor/css/wangEditor.min.css">
<link rel="stylesheet" href="__PUBLIC__/static/admin/wangEditor/css/styles/ir_black.css">
<link rel="stylesheet" href="__PUBLIC__/static/admin/uploadifive/uploadifive.css">
<style>
.uploadifive-button{border:none;font-size: 16px;line-height: 37px!important; border-radius:1px; height: 37px!important;background:#3bb4f2;color:#fff;width: 100%!important}
    </style>
<div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">个人资料</strong> / <small>Personal information</small></div>
      </div>

      <hr/>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-3 am-u-md-push-9">

          <div class="am-panel am-panel-default">
            <div class="am-panel-bd">
              <form class="am-form" id="chageavatar">
                <fieldset>
                  <legend>修改头像</legend>
                    <div>
                        <div style="overflow: hidden;">
                          <img style="display:block; margin: 25px auto;cursor:pointer;" src="<?php echo session('userinfo')[0]['avatar']==''?'__PUBLIC__/static/admin/i/avatar.jpg':session('userinfo')[0]['avatar'];?>" id="avatar_show" alt="头像" class="am-circle" width="100%">
                        </div>
                        <div style="margin: 15px auto">
                         <input type="file" name="cover" class="am-btn am-btn-secondary" id="avatar_upload" onclick="return false;" />
                                <div id="tip-queue" style="display: none"></div>
                        </span>
                        </div>
                        <input type="hidden" name="" id="image" value="">
                      </div>
                </fieldset>
              </form>
            </div>
          </div>

          <div class="am-panel am-panel-default">
            <div class="am-panel-bd">
              <form class="am-form" id="chagepass">
                <fieldset>
                  <legend>修改密码</legend>

                  <div class="am-form-group">
                    <label for="oldpass">旧密码</label>
                    <input type="text" class="" id="oldpass" placeholder="输入旧密码" name="oldpass">
                  </div>

                  <div class="am-form-group">
                    <label for="newpass">新密码</label>
                    <input type="text" class="" id="newpass" placeholder="设置新密码" id="newpass">
                  </div>

                  <p><button type="submit" class="am-btn am-btn-primary">修改</button></p>
                </fieldset>
              </form>
            </div>
          </div>

        </div>

        <div class="am-u-sm-12 am-u-md-9 am-u-md-pull-3">
          <form class="am-form am-form-horizontal" id="userinfo">
            <div class="am-form-group">
              <label for="user-name" class="am-u-sm-3 am-form-label">用户名 / Name</label>
              <div class="am-u-sm-9">
                <input type="text" id="user-name" placeholder="输入你的用户名 / Name" name="username" value="{$userInfo['username']}" readonly="true">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-github" class="am-u-sm-3 am-form-label">GitHub / GitHub</label>
              <div class="am-u-sm-9">
                <input type="text" id="user-github" placeholder="输入你的GitHub / GitHub" name="github" value="{$userInfo['github']}">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-email" class="am-u-sm-3 am-form-label">电子邮件 / Email</label>
              <div class="am-u-sm-9">
                <input type="email" id="user-email" placeholder="输入你的电子邮件 / Email" name="email" value="{$userInfo['email']}">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-weibo" class="am-u-sm-3 am-form-label">weibo / Weibo</label>
              <div class="am-u-sm-4">
                <input type="tel" id="user-weibo" placeholder="输入你的微博昵称 / Weibo" name="weibo" value="{$userInfo['weibo']}">
              </div>
              <div class="am-u-sm-5">
                <input type="tel" id="user-weibo_num" placeholder="输入你的微博ID / WeiboID" name="weibo_num" value="{$userInfo['weibo_num']}">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-QQ" class="am-u-sm-3 am-form-label">QQ / QQ</label>
              <div class="am-u-sm-9">
                <input type="number" pattern="[0-11]*" id="user-QQ" placeholder="输入你的QQ / QQ" name="qq" value="{$userInfo['qq']}">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-gitosc" class="am-u-sm-3 am-form-label">GitOSC / GitOSC</label>
              <div class="am-u-sm-9">
                <input type="text" id="user-gitosc" placeholder="输入你的GitOSChina / GitOSChina" name="gitosc" value="{$userInfo['gitosc']}">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-intro" class="am-u-sm-3 am-form-label">简介 / Intro</label>
              <div class="am-u-sm-9">
                <textarea id="editor-description" name="description" style="display:none;" rows="20">{$userInfo['description']}
                </textarea>
                <!-- <textarea class="" rows="12" id="user-intro" placeholder="输入个人简介" name="description"></textarea> -->
              </div>
            </div>

            <div class="am-form-group">
              <div class="am-u-sm-9 am-u-sm-push-3">
                <button type="submit" class="am-btn am-btn-primary">保存修改</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
    </block>

    <block name="js">
    <script src="__PUBLIC__/static/admin/wangEditor/wangEditor.min.js"></script>
    <script src="__PUBLIC__/static/admin/uploadifive/jquery.uploadifive.js"></script>
    <script type="text/javascript">
        //uploadifive
        $(function(){
            $('#avatar_upload').uploadifive({
                'formData'     : {'type':'avatar'},
                'uploadScript' : "{:U('upload/uploadimage')}",
                'multi':false,
                'buttonText'   : '选择图片',   //按钮显示文字
                'queueID'      : 'tip-queue', //提示信息放置目标
                'fileType'     : 'image/*',   //允许上传文件类型
                'onSelect': function (file) {
                    layer.load(1);
                },
                'onUploadComplete': function(file,data,response){
                    layer.closeAll('loading');
                    data= $.parseJSON(data);
                    if(!data.status){
                        alert(data.msg);
                    }else{
                        layer.msg('图片上传完毕');
                        $("#avatar_show").attr('src',data.msg);
                        // 更新数据
                        $.post('{:U("__ACTION__")}',{'avatar':data.msg},function(){
                          if(res.status){
                            layer.msg(res.msg);
                          }else{
                            layer.alert(res.msg);
                          }
                        });
                    }
                }
            });
        })
      </script>
      <script type="text/javascript">
      // 阻止输出log
        wangEditor.config.printLog = false;

        var editor = new wangEditor('editor-description');

        // 上传图片
        editor.config.uploadImgUrl = "{:U('upload/uploadimage')}";
        
        editor.config.uploadHeaders = {
             'Accept' : 'image/*'
        };
         editor.config.uploadImgFileName = 'Filedata';

        // 隐藏网络图片
        // editor.config.hideLinkImg = true;

        // 表情显示项
        editor.config.emotionsShow = 'value';
        editor.config.emotions = {
            'default': {
                title: '默认',
                data: "__PUBLIC__/static/admin/wangEditor/emotions.data"
            },
            'weibo': {
                title: '微博表情',
                data: [
                    {
                        icon: 'http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/7a/shenshou_thumb.gif',
                        value: '[草泥马]'
                    },
                    {
                        icon: 'http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/60/horse2_thumb.gif',
                        value: '[神马]'
                    },
                    {
                        icon: 'http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/bc/fuyun_thumb.gif',
                        value: '[浮云]'
                    },
                    {
                        icon: 'http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c9/geili_thumb.gif',
                        value: '[给力]'
                    },
                    {
                        icon: 'http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/f2/wg_thumb.gif',
                        value: '[围观]'
                    },
                    {
                        icon: 'http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/70/vw_thumb.gif',
                        value: '[威武]'
                    }
                ]
            }
        };
        // 普通菜单配置
         editor.config.menus = ['source','|','bold','forecolor',
             'bgcolor','quote','fontfamily','head','orderlist','alignleft','aligncenter',
             'alignright','link','|','unlink','emotion','img','insertcode','fullscreen'];
        // 自定义load事件
        editor.config.uploadImgFns.onload = function (resultText, xhr) {
            // resultText 服务器端返回的text
            // xhr 是 xmlHttpRequest 对象，IE8、9中不支持
            resultText= $.parseJSON(resultText);
            // 如果 resultText 是图片的url地址，可以这样插入图片：
            editor.command(null, 'insertHtml', '<img src="' + resultText.msg + '" style="max-width:100%;"/>');
            // 如果不想要 img 的 max-width 样式，也可以这样插入：
            // editor.command(null, 'InsertImage', resultText);
        };
        // 自定义timeout事件
        editor.config.uploadImgFns.ontimeout = function (xhr) {
            // xhr 是 xmlHttpRequest 对象，IE8、9中不支持
            alert('上传超时');
        };

        // 自定义error事件
        editor.config.uploadImgFns.onerror = function (xhr) {
            // xhr 是 xmlHttpRequest 对象，IE8、9中不支持
            alert('上传错误');
        };
        editor.create();

        $("#userinfo").submit(function(){
          var description=editor.$txt.html();
          var weibo=$("#user-weibo").val();
          var weibo_num=$("#user-weibo_num").val();
          var qq=$("#user-QQ").val();
          var email=$("#user-email").val();
          var gitosc=$("#user-gitosc").val();
          var github=$("#user-github").val();
          $.post('{:U("__ACTION__")}',{
            'description':description,
            'weibo':weibo,
            'weibo_num':weibo_num,
            'qq':qq,
            'email':email,
            'github':github,
            'gitosc':gitosc
          },function (res) {
              if(res.status){
                layer.msg(res.msg);
                deleteCache();
              }else{
                layer.alert(res.msg,{icon:5});
              }
          });
          return false;
        });

        $("#chagepass").submit(function(){
          var oldpass=$("#oldpass").val();
          var newpass=$("#newpass").val();
          if(oldpass==newpass){
            layer.alert('两次密码一样！');
            return false;
          }
          $.post('{:U("__ACTION__")}',{'oldpass':oldpass,'newpass':newpass},function(res){
              if(res.status){
                layer.msg(res.msg);
              }else{
                layer.alert(res.msg,{icon:5});
              }
          });
          return false;
        })
      </script>
    </block>